ARG ARCH=riscv64
ARG BASE_IMAGE=xfan1024/openeuler:24.03-riscv64

# Use multiarch/qemu-user-static to enable other platforms to build this image
FROM multiarch/qemu-user-static:${ARCH} as qemu

# Build from source
FROM ${BASE_IMAGE} AS builder
ARG ARCH=riscv64
WORKDIR /root/rpmbuild/SOURCES
COPY --from=qemu /usr/bin/qemu-${ARCH}-static /usr/bin
RUN dnf install -y rpm-build rpmdevtools dnf-plugins-core git;\
    git clone --branch v6.0.0 --depth=1 https://gitee.com/opengauss/riscv .;\
    yum-builddep -y opengauss-server.spec;\
    spectool -g opengauss-server.spec;\
    rpmbuild -ba opengauss-server.spec;

# runtime
FROM xfan1024/openeuler:24.03-riscv64
ARG ARCH=riscv64
COPY --from=qemu /usr/bin/qemu-${ARCH}-static /usr/bin
COPY --from=builder /root/rpmbuild/RPMS/riscv64/*.rpm /root/
RUN dnf install -y /root/*.rpm;
# TODO: Add entrypoint
EXPOSE 5432